package com.roy.controller.kcaptcha;

import com.baomidou.kaptcha.Kaptcha;
import com.ramostear.captcha.HappyCaptcha;
import com.ramostear.captcha.support.CaptchaStyle;
import com.ramostear.captcha.support.CaptchaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ：楼兰
 * @date ：Created in 2021/1/15
 * @description:
 **/

@RestController
@RequestMapping("/kcaptcha/")
public class KcaptchaController {

    @Resource
    private Kaptcha kaptcha;

    @PostMapping("/login")
    public Object login(String verifyCode, HttpServletRequest request){
        boolean result = kaptcha.validate(verifyCode, 60);
        if(result){
            return "login";
        }else{
            return null;
        }
    }


    @GetMapping("/verifyCode")
    public void generateImg(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        kaptcha.render();
    }
}
